package com.lunker.moneyrecord;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.EditText;

public class TextInputDialog extends Dialog implements android.view.View.OnClickListener {
	
	private EditText inputText = null;
	private Button yesButton = null;
	private Button noButton = null;
	private OnSetStringListener listener = null;
	
	public TextInputDialog(Context context) {
		super(context);
		setContentView(R.layout.text_input_dialog);
		setTitle(R.string.please_enter_comment);
		
		inputText = (EditText) findViewById(R.id.edt_input_text);
		yesButton = (Button) findViewById(R.id.btn_yes);		
		noButton = (Button) findViewById(R.id.btn_no);
		yesButton.setOnClickListener(this);
		noButton.setOnClickListener(this);
		getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
	}

	public TextInputDialog(Context context, OnSetStringListener lsr) {
		this(context);
		listener = lsr;
	}

	@Override
	public void onClick(View v) {
		dismiss();
		
		switch (v.getId()) {
		case R.id.btn_yes:
			if (listener != null) {
				listener.onSetString(inputText.getText().toString());
			}
			break;
		case R.id.btn_no:
			//Do nothing.
			break;
		}
	}
	
	public void setOnSetStringListener (TextInputDialog.OnSetStringListener lsr) {
		listener = lsr;
	}
	
	public static interface OnSetStringListener {
		abstract void onSetString (String str);
	}
}
